//
//  Common.m
//  Payment
//
//  Created by  ztryxh on 2018/2/27.
//  Copyright © 2018年 ebo. All rights reserved.
//

#import "Common.h"
#import <SAMKeychain.h>
//#import "MyInfoTools.h"
@implementation Common
#pragma mark 倒计时按钮提示

+(void)countDown:(UIButton *)btn countdown:(int)kcountdown{
    __block int countdown;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        dispatch_sync(dispatch_get_main_queue(), ^{
            [btn setEnabled:NO];
            countdown=kcountdown;
//            [btn setBackgroundColor:[UIColor lightGrayColor]];
        });
        
        while (countdown>0) {
            
            if (--countdown>0) {
                
                dispatch_sync(dispatch_get_main_queue(), ^{
                    [btn setTitle:[NSString stringWithFormat:@"%dS ",countdown] forState:UIControlStateNormal];
                });
                [NSThread sleepForTimeInterval:1.0f];
            }
            else
            {
                dispatch_sync(dispatch_get_main_queue(),^{
                    [btn setTitle:@"发送" forState:UIControlStateNormal];
//                    [btn setBackgroundColor:kLoginBtnColor];
                    [btn setEnabled:YES];
                });
                
            }
        }
    });
}
#pragma mark - 获取设备udid
+ (NSString *)getDeviceId
{
    NSString * currentDeviceUUIDStr = [SAMKeychain passwordForService:@" "account:@"uuid"];
    if (currentDeviceUUIDStr == nil || [currentDeviceUUIDStr isEqualToString:@""])
    {
        NSUUID * currentDeviceUUID  = [UIDevice currentDevice].identifierForVendor;
        currentDeviceUUIDStr = currentDeviceUUID.UUIDString;
        currentDeviceUUIDStr = [currentDeviceUUIDStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
        currentDeviceUUIDStr = [currentDeviceUUIDStr lowercaseString];
        [SAMKeychain setPassword: currentDeviceUUIDStr forService:@" "account:@"uuid"];
    }
    return currentDeviceUUIDStr;
}
#pragma mark - 判断安全等级状况
@end
